package org.example.maven.mapper;

import org.apache.ibatis.annotations.*;
import org.example.maven.pojo.department.list.AddDepartment;
import org.example.maven.pojo.department.list.DepartmentAllDetail;
import org.example.maven.pojo.department.list.DepartmentListTable;
import org.example.maven.pojo.department.list.DepartmentSelect;

import java.util.List;

@Mapper
public interface departmentMapper {
    //获取部门信息listTabel
    @Select("select *from department_user")
    List<DepartmentAllDetail> getAllDepartmentList();

    //获取特定的部门信息
    List<DepartmentAllDetail> getSpecieDepartment(String deptName,Integer status);

    //获取部门单选框的选项
    @Select("select dept_id as value,dept_name as label from department where is_deleted=0")
    List<DepartmentSelect> getDepartmentSelect();

    //添加部门
    void addDepartment(AddDepartment addDepartment);

    //根据id搜索部门
    @Select("select dept_id as id,dept_name,parent_id,manager_id,status from department where dept_id=#{id} and is_deleted=0")
    AddDepartment getDepartmentById(Integer id);

    //根据id更新部门信息
    void updateDepartmentById(AddDepartment addDepartment);

    //更新已经逻辑删除的部门信息
    @Update("update department set dept_name=#{deptName},parent_id=#{parentId},manager_id=#{managerId},status=#{status},create_time=#{time},update_time=NULL,is_deleted=#{isDeleted} where dept_id=#{id}")
    void updateDeletedDepartment(AddDepartment addDepartment);

    //逻辑删除部门
    @Update("update department set is_deleted=1 where dept_id=#{id}")
    void deleteDepartment(Integer Id);

    //判断添加的部门是否存在
    @Select("SELECT *from department where dept_name=#{deptName} and is_deleted=0")
    AddDepartment findDepartmentByName(String deptName);

    //判断添加的部门在删除部门了是否存在
    @Results({
            @Result(property = "id", column = "dept_id"),
    })
    @Select("select *from department where dept_name=#{deptName} and is_deleted=1")
    AddDepartment findDepartmentIsDelete(String deptName);
}
